@extends('backend::layout')

@section('title', '用户列表')

@section('content')
    <div class="card border-no">
        <div class="card-body">
            @if($currentAdmin->allow('user/add'))
                <div class="row">
                    <div class="clearfix"></div>
                    <div class="col-md-12 col-sm-12 col-xs-12 pull-right">
                        <p>
                            <a href="{{ route('admin.user.add') }}" class="btn btn-primary btn-sm">新增用户</a>
                        </p>
                    </div>
                </div>
            @endif
                <form method="get">
                    <div class="row">
                        <div class="clearfix"></div>
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <label class="col-md-2 col-sm-12">
                                <input class="form-control" type="text" placeholder="姓名" name="name" value="{{ old("name") ?: (isset($query['name']) ? $query['name'] : '') }}" />
                            </label>
                            <label class="col-md-2 col-sm-12">
                                <input class="form-control" type="text" placeholder="手机号" name="phone" value="{{ old("phone") ?: (isset($query['phone']) ? $query['phone'] : '') }}" />
                            </label>

                            @if(!$isSchool)
                                <label class="col-md-2 col-sm-12">
                                    <select class="form-control" id="agency" name="agency_id">
                                        <option  value="">--{{__("Agency")}}--</option>
                                        @foreach($agencies as $val)
                                            <option value="{{ $val->id }}" @if(old('agency_id') === $val->id || (old('agency_id') === null && (isset($query['agency_id']) && $query['agency_id'] ==  $val->id )) ) selected @endif >{{ $val->name }}</option>
                                        @endforeach
                                    </select>
                                </label>
                            @endif

                            <label class="col-md-2 col-sm-12">
                                <button class="btn btn-primary btn-sm">搜索</button>
                            </label>
                        </div>
                    </div>
                </form>
{{--            <h4 class="text-black f-20">用户列表</h4>--}}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">{{ __('Username') }}</th>
                        <th scope="col">{{ __('Mobile') }}</th>
                        <th scope="col">{{ __('Type') }}</th>
                        <th scope="col">是否启用</th>
                        <th scope="col">{{ __('Create Time') }}</th>
                        <th scope="col">{{ __('Update Time') }}</th>
                        <th scope="col">{{ __('Options') }}</th>
                    </tr>
                    </thead>
                    <tbody>
                    @if(isset($users))
                        @foreach($users as $idx => $item)
                            <tr>
                                <th scope="row">{{ $idx + 1 }}</th>
                                <td>{{ $item->name }}</td>
                                <td>{{ $item->phone }}</td>
                                <td>{{ $item->type->name }}</td>
                                <td>
                                    @if(!empty($currentAdmin) && $currentAdmin->allow('user/view'))

                                        <a href="{{ route('admin.user.enable', ['id' => $item->id]) }}" class="" >&nbsp;
                                            &nbsp;<button type="button" class="btn btn-sm {{ $item->status == 1 ? "btn-success" : "btn-danger" }}">{{ $item->status == 1 ? "已启用" : "已禁用" }}</button>
                                        </a>
                                    @else
                                        {{ $item->status == 1 ? "启用" : "禁用" }}
                                    @endif
                                </td>
                                <td>{{ $item->created_at }}</td>
                                <td>{{ $item->updated_at }}</td>
                                <td>
                                    @if(!empty($currentAdmin) && $currentAdmin->allow('child/index'))
                                        <a href="{{ route('admin.child.index', ['user_id' => $item->id]) }}" class="text-danger" title="学生">&nbsp;&nbsp;<i class="fa fa-users"></i></a>
                                    @endif
                                    @if(!empty($currentAdmin) && $currentAdmin->allow('user/view'))
                                        <a href="{{ route('admin.user.view', ['id' => $item->id]) }}" class="text-primary" title="{{ __('View') }}">&nbsp;&nbsp;<i class="fa fa-eye"></i></a>
                                    @endif
                                    @if(!empty($currentAdmin) && $currentAdmin->allow('user/edit'))
                                        <a href="{{ route('admin.user.edit', ['id' => $item->id]) }}" class="text-info" title="{{ __('Edit') }}">&nbsp;&nbsp;<i class="fa fa-pencil"></i></a>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    @endif
                    </tbody>
                </table>
            </div>
            <div class="row">
                <div class="clearfix"></div>
                <div class="col-md-12 col-sm-12 col-xs-12 pull-right">
                    @if(isset($users))
                        {{ $users->links() }}
                    @endif
                </div>
            </div>
        </div>
    </div>
@stop